# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libc++abi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.5.0
pkgrel=1
pkgdesc='A new implementation of low level support for a standard C++ library'
url='https://libcxxabi.llvm.org'
license=('custom:University of Illinois/NCSA Open Source License')
arch=('any')
# gcc-libs needed for libgcc_s, because mingw-w64 doesn't use a pure compiler-rt clang
depends=()
makedepends=("${MINGW_PACKAGE_PREFIX}-clang"
             "${MINGW_PACKAGE_PREFIX}-cmake")
source=(https://releases.llvm.org/$pkgver/libcxxabi-${pkgver}.src.tar.xz{,.sig}
        https://releases.llvm.org/$pkgver/libcxx-${pkgver}.src.tar.xz{,.sig})
sha256sums=('53c6be6a2dd2371f6d92c968cb8a59fbe13c6153583025433df067f706bfacd9'
            'SKIP'
            '8045da845a63e50c201939eda8290d45e5752a9385d4d626214300d4a4d0b1c0'
            'SKIP')

prepare() {
  cd ${srcdir}/libcxxabi-${pkgver}.src
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  export CXX="${MINGW_PREFIX}/bin/clang++"
  export CC="${MINGW_PREFIX}/bin/clang"
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX:PATH=${pkgdir}${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DLIBCXXABI_LIBCXX_INCLUDES=${srcdir}/libcxx-${pkgver}.src/include \
    ../libcxxabi-${pkgver}.src
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
}
